//
//  WFHuaTiTableViewCell.m
//  WangyiFangzuo
//
//  Created by 瑜 on 16/9/13.
//  Copyright © 2016年 111. All rights reserved.
//

#import "WFHuaTiTableViewCell.h"
#import <AFNetworking.h>
#import "WFCollectionModel.h"
#import "WFHuaTiCollectionViewCell.h"
@implementation WFHuaTiTableViewCell
static NSString *ID = @"cell";
- (NSMutableArray *)arrModel
{
    if(!_arrModel)
    {
        _arrModel = [NSMutableArray array];
    }
    return _arrModel;
}
- (void)awakeFromNib {
    [self loadData];
    _collection.dataSource = self;
    _collection.delegate = self;
    _collection.showsHorizontalScrollIndicator = NO;
    [self.collection registerNib:[UINib nibWithNibName:@"WFHuaTiCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:ID];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arrModel.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WFHuaTiCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    WFCollectionModel *model = self.arrModel[indexPath.row];
    cell.model = model;
    return cell;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)loadData
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    [manager GET:@"http://c.3g.163.com/recommend/getChanRecomNews?channel=T1460094487214&passport=&devId=ppVGHroke1xmdzWe7TaLdXBnZwrKAC8kvcYlZcUdzjdDvhuyLLRgxghPPfKwjylo&offset=0&size=5&version=15.0&spever=false&net=wifi&lat=&lon=&ts=1473741371&sign=%2FcRJR%2BQcPOkuzFiOphPHeKcIBthEAmO5dBWUqovj3uF48ErR02zJ6%2FKXOnxX046I&encryption=1&canal=appstore" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        for(NSDictionary *dict in responseObject[@"话题"])
        {
            WFCollectionModel *model = [WFCollectionModel modelWithDict:dict];
            [self.arrModel addObject:model];
        }
        [self.collection reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
}
+ (instancetype)cell
{
    return [[[NSBundle mainBundle] loadNibNamed:@"WFHuaTiTableViewCell" owner:nil options:nil] lastObject];
}
@end
